package com.zhentao.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.domain.SysSite;
import com.zhentao.domain.SysUserSite;
import com.zhentao.domain.vo.Result;
import com.zhentao.mapper.SysSiteMapper;
import com.zhentao.service.SysSiteService;
import com.zhentao.service.SysUserSiteService;
import com.zhentao.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 86133
* @description 针对表【sys_site】的数据库操作Service实现
* @createDate 2024-08-20 17:17:50
*/
@Service
public class SysSiteServiceImpl extends ServiceImpl<SysSiteMapper, SysSite>
    implements SysSiteService{
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private UserUtils userUtils;
    @Override
    public Result<List<SysSite>> getSiteList() {
        List<SysSite> list = this.list();
        redisTemplate.opsForValue().set("redis:"+userUtils.GetUserId(), JSON.toJSONString(list));
        return Result.build(list, 200, "查询成功");
    }


    @Override
    public Result<List<SysSite>> getListByRedis(String value) {
        String s = redisTemplate.opsForValue().get("redis:"+userUtils.GetUserId());
        List<SysSite> sysSites = JSON.parseArray(s, SysSite.class);
        if (value == null ){
            return Result.build(sysSites, 200, "查询成功");
        }
       List<SysSite> list = new ArrayList<>();
        for (SysSite sysSite : sysSites) {
            if (sysSite.getAddress().contains(value)){
                list.add(sysSite);
            }
        }
        return Result.build(list, 200, "查询成功");
    }
}




